package com.zzyl.controller.customer;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectPageQueryDto;
import com.zzyl.dto.OrderDto;
import com.zzyl.dto.OrderPageQueryDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.service.OrderService;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "客户订单管理")
@RestController
@RequestMapping("/customer/orders")
@Slf4j
public class CustomOrderController {


    @ApiOperation("根据编号查询护理项目信息")
    @GetMapping("/project/{id}")
    public ResponseResult<NursingProjectVo> getProjectById(@PathVariable("id") Long id){
        log.info("根据Id查询护理项目:{}", id);

        NursingProjectVo nursingProjectVo = nursingProjectService.findNursingProjectById(id);
        return ResponseResult.success(nursingProjectVo);
    }


    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation("分页查询护理项目列表")
    @GetMapping("/project/page")
    public ResponseResult<PageBean<NursingProjectVo>> searchProjectPage(NursingProjectPageQueryDto dto){
        log.info("护理项目分页查询：{}", dto);
        PageBean<NursingProjectVo> pageBean = nursingProjectService.pageQuery(dto);
        return ResponseResult.success(pageBean);
    }



    @Autowired
    private OrderService orderService;

    @ApiOperation("分页查询订单")
    @GetMapping("/order/page")
    public ResponseResult<PageBean<OrderVo>> searchOrders(OrderPageQueryDto dto) {
        PageBean<OrderVo> pageBean = orderService.searchOrders4Customer(dto);
        return ResponseResult.success(pageBean);
    }

    @ApiOperation("校验老人订单")
    @PostMapping("check")
    public ResponseResult<Void> checkOlderOrder(@RequestBody OrderDto dto) {
        orderService.checkOlderOrder(dto);
        return ResponseResult.success();
    }

    @ApiOperation("新增老人护理项目订单")
    @PostMapping()
    public ResponseResult<Void> addElderOrder(@RequestBody OrderDto dto) {
        orderService.addElderOrder(dto);
        return ResponseResult.success();
    }
}

